<?php
namespace App\Models\Lession;


use App\Models\User\User;
use App\Libs\Helper\CommonHelper;
class CommentCopy extends \App\Libs\Base\BaseModel
{
    protected $__TABLE__ = 't_jia_lesment';

	public function beforeValidation()
	{
	 self::skipValidation(['ctime'] , $this );
	}

    public function initialize()
    {
        parent::initialize();
        $this->hasOne("id", "App\Models\Lession\Comment", "fid",['alias'=> 'reply']);
//        $this->belongTo('uid','APP\Models\','id',['alias'=> 'userInfo']);
    }

    public function getDoubleUserName($model){
	    $uidArray = [$model->from_uid,$model->to_uid];
        $matchUser = User::findAll([
            'id in ({dsf:array})',
            'bind'=> ['dsf'=>$uidArray],
            'columns' =>'id,username'
        ])->toArray();
        if(empty($matchUser)){
            return [$model->from_uid=>'匿名用户',$model->to_uid=> '匿名用户'];
        }
        $transUser = CommonHelper::setColToKey($matchUser,'id');
        return [$model->from_uid=>$transUser[$model->from_uid]['username'],$model->to_uid=>$transUser[$model->to_uid]['username']];

    }

    public function getSingleUserName($uid){
        $matchUser = User::findOne([
            'id=?1',
            'bind' => [1=>$uid],
            'columns'=>'id,username'
        ]);

        return $matchUser->username;
    }



}
